
package kaizone.haining.chaobohui.widget;

import kaizone.haining.chaobohui.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class CBHHead extends RelativeLayout implements OnClickListener {

    private ImageView mMenuImageView;

    private TextView mTitltTextView;

    private Button mButton;

    private OnLeftImageClickListener mLeftClickListener;

    private OnRightClickListener mRightClickListener;

    public CBHHead(Context context) {
        super(context);
    }

    public CBHHead(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {

    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mMenuImageView = (ImageView) findViewById(R.id.show_menu);
        mMenuImageView.setOnClickListener(this);
        mTitltTextView = (TextView) findViewById(R.id.title);
        mButton = (Button) findViewById(R.id.btn);
        mButton.setOnClickListener(this);
        mButton.setVisibility(View.GONE);
    }

    public void setText(String text) {
        mTitltTextView.setText(text);
    }

    public void setTextColor(int color) {
        mTitltTextView.setTextColor(color);
    }

    public void setMenuVisibility(int visibility) {
        mMenuImageView.setVisibility(visibility);
    }

    public void setLeftImageResource(int resId) {
        mMenuImageView.setImageResource(resId);
    }

    public void setLeftImageBackState() {
        mMenuImageView.setImageResource(R.drawable.btn_backwhite);
    }

    public void setLeftImageMenuState() {
        mMenuImageView.setImageResource(R.drawable.x_head_menu);
    }
    
    public void  addRightButton(){
        mButton.setVisibility(View.VISIBLE);
    }
    
    public void  removeRightButton(){
    	mButton.setVisibility(View.GONE);
    }

    @Override
    public void onClick(View v) {
        if (v == mMenuImageView) {
            if (mLeftClickListener != null) {
                mLeftClickListener.onLeftImageClick(v);
            }
        } else if (v == mButton) {
            if (mRightClickListener != null) {
                mRightClickListener.onRightClick(v);
            }
        }
    }

    public OnLeftImageClickListener getListener() {
        return mLeftClickListener;
    }

    public void setLeftImageListener(OnLeftImageClickListener listener) {
        this.mLeftClickListener = listener;
    }

    public void setRightClickListener(OnRightClickListener listener) {
        this.mRightClickListener = listener;
    }

    public interface OnLeftImageClickListener {
        void onLeftImageClick(View v);
    }

    public interface OnRightClickListener {
        void onRightClick(View v);
    }

}
